﻿@model IEnumerable<ElCharro01.Models.Product>
@using ElCharro01.Helpers
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
<div class="paddalo">
    <h2 class="centered">
        Gestione Prodotti</h2>
    <p>@Html.ActionLink("Crea Nuovo Prodotto", "Create")</p>
    <div>
        @using (Html.BeginForm("Index", "Product", FormMethod.Get))
        { 
            <p>
                Visualizza:
                @Html.DropDownList("categoryId", new SelectList(ViewBag.CategoryList, "ID", "Nome"), "Tutto", new { onchange = "this.form.submit();" })
            </p>
        }
    </div>
    <table>
        <tr>
            <th>
                Nome
            </th>
            <th>
                Descrizione
            </th>
            <th>
                Categoria
            </th>
            <th>
                Tipo Abbigliamento
            </th>
            <th>
                Variante Per Questo Prodotto
            </th>
            <th>
                Nello Slideshow
            </th>
            <th>
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Nome)
                </td>
                <td>
                    @Html.Truncate(item.Descrizione, 13)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Category.Nome)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ClothingType.Nome)
                </td>
                <td>
                    @item.Variant.Count()
                </td>
                @using (Html.BeginForm("IntoSlideshow", "Product", new { ProductId = item.ID }))
                {
                    <td>
                        @Html.CheckBox("slideshow", item.InSlideShow, new { onchange = "this.form.submit();" })
                    </td>
                }
                <td>
                    @Html.ActionLink("Aggiungi Variante", "Create", "Variant", new { id = item.ID }, new { })
                    |
                    @Html.ActionLink("Mostra Varianti", "ShowVariantOfProduct", "Variant", new { ProductID = item.ID }, new { })
                    |
                    @Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
                    @Html.ActionLink("Elimina", "Delete", new { id = item.ID })
                </td>
            </tr>
        }
    </table>
</div>
